﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SchoolManagementSystem.Controls;
using CoreData;
using Helper;
using DevExpress.XtraEditors.Controls;
using SchoolManagementSystem.Forms.BusinessForm;

namespace SchoolManagementSystem.Details
{
    //Học viên
    public partial class StudentUC : DetailUC
    {
        /// <summary>
        /// //giữ lại mã lớp ban đầu đề phòng trường hợp chuyển lớp phải cập nhật lại bảng điểm
        /// Nêu mã lớp này thuộc ngành khác thì mới cập nhật
        /// </summary>
        long ClassTemp = 0;
        long StatusID;//luu lai trang thai dau tien
        KList<TypeOfFee> TypeOfFeeLst = new KList<TypeOfFee>();
        long ClassID;
        public StudentUC()
        {
            InitializeComponent();
            this.ObjectName = "học viên";
            this.Code = "Student";
            this.Type = new Student();

            TypeOfFeeLst.Add(new TypeOfFee() { ID = 1, Name = "Đóng một lần" });
            TypeOfFeeLst.Add(new TypeOfFee() { ID = 2, Name = "Đóng hai lần" });
            //TypeOfFeeLst.Add(new TypeOfFee() { ID = 3, Name = "Đóng ba lần" });
            TypeOfFeeLst.Add(new TypeOfFee() { ID = 4, Name = "Đóng bốn lần" });
            TypeOfFeeLst.Add(new TypeOfFee() { ID = 6, Name = "Đóng sáu lần" });
            LoadTypeOfFee();

          //  comboboxUC_Classold.Model = RegisterService.RegisterServices.ClassService;
          //  comboboxUC_Classold.Uc = new ClassUC();
///comboboxUC_Classold.ColumnMain = "Name";
           // comboboxUC_Classold.ColumnDisplay = "Code,Name";
           // comboboxUC_Classold.combobox.EditValueChanged += new EventHandler(comboboxUC_ClasslookUp_EditValueChanged);

            //comboboxUC_channelinfo.Model = RegisterService.RegisterServices.ChannelInfoService;
            //comboboxUC_channelinfo.Uc = new ChannelInfoUC();
            //comboboxUC_channelinfo.ColumnMain = "Name";
            //comboboxUC_channelinfo.ColumnDisplay = "Code,Name";

            //comboboxUC_studentstatus.SearchString = " Type=1";
            //comboboxUC_studentstatus.Model = RegisterService.RegisterServices.StudentStatusService;
            //comboboxUC_studentstatus.Uc = new Student_Status_UC(1);
            //comboboxUC_studentstatus.ColumnMain = "Name";
            //comboboxUC_studentstatus.ColumnDisplay = "Code,Name";
            //comboboxUC_studentstatus.combobox.EditValueChanged += new EventHandler(comboboxUC_StatuslookUp_EditValueChanged);


            masterMainUC1.Model = RegisterService.RegisterServices.StudentHistoryService;
            masterMainUC1.DetailUCControl = new Student_HistoryUC();

            spinEdit_Money.EditValue = 0;
            spinEdit_price.EditValue = 0;
            txtdiscount.Text = "0";
            CheckStudentReserved();

        }

        void comboboxUC_StatuslookUp_EditValueChanged(object sender, EventArgs e)
        {
            //if (ID > 0 && comboboxUC_studentstatus.ID !=StatusID && StatusID==2)
            //{
            //    spinEdit_Money.EditValue = TongHocPhi();
            //}
        }

        int oldtypeoffee;

        //bỏ
        void comboboxUC_ClasslookUp_EditValueChanged(object sender, EventArgs e)
        {
            if (comboboxUC_Classold.ID > 0)
            {
                dateedit_dateaddmisstion.DateTime = ((Class)RegisterService.RegisterServices.ClassService.GetByID(comboboxUC_Classold.ID)).StartDate;
               if(ID<=0)
                txtcode.Text = RegisterService.RegisterServices.StudentService.GenerateCode(comboboxUC_Classold.ID);
            }
            else
            {
                dateedit_dateaddmisstion.DateTime = DateTime.Now;
            }
            spinEdit_Money.EditValue = TongHocPhi();
        }

        void LoadTypeOfFee()
        {
            try
            {
               
                ComboBoxItemCollection coll = cbtypeoffee.Properties.Items;
                coll.BeginUpdate();
                try
                {
                    cbtypeoffee.Properties.NullText = "[Rỗng]";
                    cbtypeoffee.Properties.Items.AddRange(TypeOfFeeLst);
                }
                finally
                {
                    coll.EndUpdate();
                }
                cbtypeoffee.SelectedIndex = -1;


            }
            catch { }
        }
        String StudentID = "1=1";
        protected override long DetailDisplay()
        {
            Student data = new Student();
            Class classData = null;
            if (ID > 0)
            {
                data = (Student)RegisterService.RegisterServices.StudentService.GetByID(ID);
                StudentID = data.ID.ToString();
                StatusID = data.Status;
                ClassID = data.ClassID;
                classData = RegisterService.RegisterServices.ClassService.GetByID(ClassID) as Class;             
                buttonEdit_Class.EditValue = classData.Name;
            }
            else {

                ClassID = 0;
                buttonEdit_Class.EditValue = "";
                 // data.Code = RegisterService.RegisterServices.StudentService.GenerateCode(comboboxUC_Class.ID);
            }
            try
            {
                if (data.ID <= 0)
                    data.TypeOfFee = 1;
                cbtypeoffee.SelectedItem = TypeOfFeeLst.First(c => c.ID == data.TypeOfFee); //
            }
            catch { }

            txtfirstname.Text = data.FirstName;
            txtlastname.Text = data.LastName;
            txtaddress.Text = data.Address;
            txtemail.Text = data.Email;
            memoEdit_noisinh.Text = data.PlaceOfBirth;
            txtnote.Text = data.Note;
            txtphonenum.Text = data.Phone;
            dateEdit_dateofbirth.Text = data.DateOfBirth;
            buttonEdit_Status.Tag = data.Status;
            buttonEdit_Status.Text = data.StatusExt;
            buttonEdit_Channel.Tag = data.ChannelInfoID;
            buttonEdit_Channel.Text = data.ChannelExt;
            comboboxUC_Classold.ID = data.ClassID;
            cbProvince.EditValue = data.Province;
            ClassTemp = data.ClassID;
            txtcode.Text = data.Code;
            oldtypeoffee = data.TypeOfFee;
            spinEdit_Money.EditValue = data.TotalFee;
            memoEdit_BonusCourse.Text = data.CourseBonus;
            dateEdit_Completed.DateTime = data.DateOfCompleted;
            dateEdit_Off.DateTime = data.DateOfOff;
            dateEdit_Reserve.DateTime = data.DateOfReserved;
            if (data.OriginalFee <= 0 && classData != null)
            {
                data.OriginalFee = classData.Price;
            }
            spinEdit_OriginalFee.EditValue = data.OriginalFee;

            if (data.Sex)
            {
                cbsex.SelectedIndex = 0;
            }
            else
            {
                cbsex.SelectedIndex = 1;
            }

            txtcmnd.Text = data.IndentifyNumber;

            ckinfo.Checked = data.InfoStatus;//trang thai thu hô sờ
            dateedit_register.DateTime = data.RegisterDate;
            if (ID > 0)
            {
                dateedit_dateaddmisstion.DateTime = data.DateOfAdmission;
            }
            txtdiscount.Text = data.Discount.ToString();
            spinEdit_price.EditValue = data.Bonus; //học phi duoc tang them
            data.PlaceOfBirth = memoEdit_noisinh.Text;
            ckbangquydinh.Checked = data.SpecifiedTable;
            ckcmnd.Checked = data.CMND;
            ckdonxinnhaphoc.Checked = data.AppforAdmission;
            ckhinh46.Checked = data.Image4x6;
            ckcontract.Checked = data.ContractEdu;
            ckcompleted.Checked = data.IsCompleted;
            if (data.Active)//neu khoa lai thì ân hết control đi
            {
                SetEnable(false);
            }
            else
            {
                SetEnable(true);
            }

            //lay phi bao luu
            if (data.ID > 0)
            {
                var receiptvoucherfee = RegisterService.RegisterServices.ReceiptVoucherFeeService.GetByVoucherFeeSave(data.ID);
                if (receiptvoucherfee != null)
                {
                    txtphibaoluu.Text = StringHelper.FormatCurrencyVN(receiptvoucherfee.Money) + " - ngày đóng " + receiptvoucherfee.ReceiptVoucherCreateDateExt.ToShortDateString() + " - Mã phiếu thu " + receiptvoucherfee.ReceiptVoucherCodeExt;
                }
                else
                {
                    txtphibaoluu.Text = "0 đ";
                }
            }
            else {
                txtphibaoluu.Text = "0 đ";
            }

            if (data.InfoStatus == true)
                lblhoso.Text = "Hồ sơ đã nộp đầy đủ";
            else
                lblhoso.Text = "Chưa nộp đủ hồ sơ";

            

            masterMainUC1.SearchString = " StudentID='" + StudentID + "'";
            masterMainUC1.DetailUCControl.SearchString = " StudentID='" + StudentID + "'";

            return ID;

        }

        private void CheckStudentReserved()
        {
            var StudentReserved = RegisterService.RegisterServices.StudentService.GetListStudentReserved();
            if (StudentReserved != null && StudentReserved.Count != 0)
            {
                cmdXemBaoluu.Visible = true;
                lbldanhsachbaoluusaphethan.Text = "Hiện tại đang có học viên đã bảo lưu hơn 4 tháng, vui lòng bấm vào danh sách để xem chi tiết";
            }
            else
            {
                cmdXemBaoluu.Visible = false;
                lbldanhsachbaoluusaphethan.Text = string.Empty;
            }
        }
        
        protected override long Save()
        {
            //hoc vien phai co them ngay nhap hoc va ngay dang ky hoc
            Student data = new Student();
            if (ID > 0)
            {
                data = (Student)RegisterService.RegisterServices.StudentService.GetByID(ID);

            }
            if (data.ID <= 0)
            data.Code = RegisterService.RegisterServices.StudentService.GenerateCode(ClassID);
            data.Name = txtfirstname.Text+" "+ txtlastname.Text;
            data.LastName = txtlastname.Text;
            data.FirstName = txtfirstname.Text;
            if (cbProvince.SelectedItem == null)
                data.Province = "";
            else
               data.Province = cbProvince.SelectedItem.ToString();
            data.PlaceOfBirth = memoEdit_noisinh.Text;
            data.Note = txtnote.Text;
            data.IsCompleted = ckcompleted.Checked;
            data.Active = false; ; //khóa
            data.DateOfBirth = dateEdit_dateofbirth.Text;
            data.Address = txtaddress.Text;
            data.Bonus = int.Parse(spinEdit_price.EditValue.ToString());
            data.ClassID = ClassID;// comboboxUC_Classold.ID;
            data.ChannelInfoID = (long)buttonEdit_Channel.Tag;
            data.DateOfAdmission = dateedit_dateaddmisstion.DateTime;
            data.RegisterDate = dateedit_register.DateTime;
            data.Discount = int.Parse(txtdiscount.Text);
            data.Email = txtemail.Text;
            data.IndentifyNumber = txtcmnd.Text;
            data.InfoStatus = ckinfo.Checked;
            data.OriginalFee = int.Parse(spinEdit_OriginalFee.EditValue.ToString());
            data.CourseBonus = memoEdit_BonusCourse.Text;
            data.DateOfReserved = dateEdit_Reserve.DateTime;
            data.DateOfOff = dateEdit_Off.DateTime;
            data.DateOfCompleted = dateEdit_Completed.DateTime;
            data.Phone = txtphonenum.Text;
            if (cbsex.SelectedIndex==0)
            {
                data.Sex = true;
            }
            else
            {
                data.Sex = false;
            }
            data.Status = (long)buttonEdit_Status.Tag;
     
            data.TypeOfFee = int.Parse(((TypeOfFee)cbtypeoffee.SelectedItem).ID.ToString());
            data.ContractEdu = ckcontract.Checked;
            data.Image4x6 = ckhinh46.Checked;
            data.SpecifiedTable = ckbangquydinh.Checked;
            data.AppforAdmission = ckdonxinnhaphoc.Checked;
            data.CMND = ckcmnd.Checked;

            if (data.Image4x6 && data.SpecifiedTable && data.CMND && data.AppforAdmission)
                data.InfoStatus = true;

            data.TotalFee = int.Parse(spinEdit_Money.EditValue.ToString());

            // neu có thay đôi hinh thức thi thực hiện đổi hình thức đóng học phí
            if (data.ID > 0)
            {
                if (oldtypeoffee > 0 && (oldtypeoffee != data.TypeOfFee))
                {
                    RegisterService.RegisterServices.StudentService.ExcuteChangeTypeOfFee(ID, data.TypeOfFee);
                    oldtypeoffee = 0;
                }
            }

            ID = RegisterService.RegisterServices.StudentService.Save(data, ref ErrorMess);

            if (data.ID <= 0 && ID>0)
            {
                //luu lai lich su mới
                Student_History historynew = new Student_History();
                historynew.StudentID = ID;
                historynew.Content = "Đã đăng ký học lớp " + ((Class)RegisterService.RegisterServices.ClassService.GetByID(data.ClassID)).Name;
                historynew.Content += " vào ngày " + DateTime.Now.ToShortDateString();
                RegisterService.RegisterServices.StudentHistoryService.Save(historynew);
            }


            //kiem tra nganh học theo mã lớp có khác hay không

            if ((ClassTemp != data.ClassID) && data.ID >0)
            {
                var newclass = data.ClassID;
                //luu lai lich su cũ
                Student_History history = new Student_History();
                history.StudentID = ID;
                history.Content = "Đã chuyển từ lớp " + ((Class)RegisterService.RegisterServices.ClassService.GetByID(ClassTemp)).Name;
                history.Content += " đến lớp " + ((Class)RegisterService.RegisterServices.ClassService.GetByID(data.ClassID)).Name;
                history.Content += " vào ngày " + DateTime.Now.ToShortDateString();
                RegisterService.RegisterServices.StudentHistoryService.Save(history);

                //lấy mã nghành
                var Branch1 = RegisterService.RegisterServices.BranchService.GetBranchByClassID(ClassTemp);
                var Branch2 = RegisterService.RegisterServices.BranchService.GetBranchByClassID(data.ClassID);

                //cập nhật lại trang thái và đồng thời khóa lại luôn
                data.Status = 8;//da chuyen lớp
                data.Active = true; //khóa lai
                data.ClassID = ClassTemp;               
                RegisterService.RegisterServices.StudentService.Save(data, ref ErrorMess);

                //trước khi nhân bản kiểm tra xem có đóng phí bảo lưu ko
                var feesave =RegisterService.RegisterServices.ReceiptVoucherFeeService.GetByVoucherFeeSave(data.ID);

                if (feesave != null)
                {
                    data.Note = data.Note + "\n" + "Học phí " + Helper.StringHelper.FormatVND(data.TotalFee) + " trừ đi cho " + Helper.StringHelper.FormatVND(feesave.Money) + " phí bảo lưu";
                    data.TotalFee = data.TotalFee - feesave.Money;
                }
                //nhân bản ra 1 dòng mới (chuyển lớp)
                data.ID = 0;
                data.Active = false;
                data.Status = 4;
                data.ClassID = newclass;
              
               
               var newid= RegisterService.RegisterServices.StudentService.SaveDuplicate(data, ref ErrorMess);

               //luu lai lich su mới
               Student_History historynew = new Student_History();
               historynew.StudentID = newid;
               historynew.Content = "Được chuyển từ lớp " + ((Class)RegisterService.RegisterServices.ClassService.GetByID(ClassTemp)).Name;
               historynew.Content += " đến lớp " + ((Class)RegisterService.RegisterServices.ClassService.GetByID(data.ClassID)).Name;
               historynew.Content += " vào ngày " + DateTime.Now.ToShortDateString();
               RegisterService.RegisterServices.StudentHistoryService.Save(historynew);


                //so sanh mã ngành
               if (Branch1.ID != Branch2.ID)
               {
                   //neu khác nnganhf thì insert mới bảng điểm
                   var subjectpointcolumn = RegisterService.RegisterServices.SubjectPointColumnService.GetSubjectPointColumnByClassID(data.ClassID);
                   if (subjectpointcolumn != null)
                   {
                       for (int i = 0; i < subjectpointcolumn.Count; i++)
                       {
                           Student_Result st_r = new Student_Result();
                           st_r.StudentID = newid;
                           st_r.Subject_PointColumnID = subjectpointcolumn[i].ID;
                           st_r.Value = 0;
                           RegisterService.RegisterServices.StudentResultService.Save(st_r);
                       }
                   }
               }
               else
               {
                   //lấy bảng điểm cũ bỏ qua
                   var OldPointdata = (List<Student_Result>)RegisterService.RegisterServices.StudentResultService.GetList("VwStudentResult.StudentID="+ID);
                   foreach (var item in OldPointdata)
                   {
                       Student_Result st_r = new Student_Result();
                       st_r.StudentID = newid;
                       st_r.Subject_PointColumnID = item.Subject_PointColumnID;
                       st_r.Value = item.Value;
                       RegisterService.RegisterServices.StudentResultService.Save(st_r);
                   }


               }
            }
            else
            {
                //kiem tra xem trong bang kết quả đã có chưa nếu có rồi thì không thêm
                var checkExist = RegisterService.RegisterServices.StudentResultService.GetByStudentID(ID);
                if (checkExist == null)
                {
                    var subjectpointcolumn = RegisterService.RegisterServices.SubjectPointColumnService.GetSubjectPointColumnByClassID(data.ClassID);
                    if (subjectpointcolumn != null)
                    {
                        for (int i = 0; i < subjectpointcolumn.Count; i++)
                        {
                            Student_Result st_r = new Student_Result();
                            st_r.StudentID = ID;
                            st_r.Subject_PointColumnID = subjectpointcolumn[i].ID;
                            st_r.Value = 0;
                            RegisterService.RegisterServices.StudentResultService.Save(st_r);
                        }
                    }
                }
            }


           

            masterMainUC1.DetailUCControl.SearchString = ID.ToString();
            return ID;
        }

        public override bool Delete(long SelectedID)
        {

            if (SchoolManagementSystem.Controls.MessageControl.ShowMessageWithResult("Việc xóa học viên này có thể sẽ ảnh hưởng đến việc hiển thị dữ liệu, bạn có đồng ý xóa ?", "Warning", MessageControl.Icon.Warning) == DialogResult.OK)
            {
                var IsDeleted = RegisterService.RegisterServices.StudentService.Delete(RegisterService.RegisterServices.StudentService.GetByID(SelectedID));

                if (IsDeleted)
                {
                    RegisterService.RegisterServices.Student_FeeService.Delete(RegisterService.RegisterServices.Student_FeeService.GetByStudentID(SelectedID));
                    RegisterService.RegisterServices.StudentFeeTimeService.Delete(RegisterService.RegisterServices.StudentFeeTimeService.GetByStudentID(SelectedID));
                    RegisterService.RegisterServices.StudentHistoryService.Delete(RegisterService.RegisterServices.StudentHistoryService.GetOneByLINQ(c=>c.StudentID.Equals(SelectedID)));
                    RegisterService.RegisterServices.StudentRatingService.Delete(RegisterService.RegisterServices.StudentRatingService.GetOneByLINQ(c => c.StudentID.Equals(SelectedID)));
                    RegisterService.RegisterServices.StudentResultService.Delete(RegisterService.RegisterServices.StudentResultService.GetByStudentID(SelectedID));
                    RegisterService.RegisterServices.StudentResultDetailService.Delete(RegisterService.RegisterServices.StudentResultDetailService.GetOneByLINQ(c => c.StudentID.Equals(SelectedID)));
                }

                //return RegisterService.RegisterServices.StudentService.UpdateIsDelete(RegisterService.RegisterServices.StudentService.GetByID(SelectedID));
                return IsDeleted;
            }
            return false;
         
        }


        private void StudentUC_Load(object sender, EventArgs e)
        {
            AddTextChanged(xtraTabPage1.Controls);
            AddTextChanged(xtraTabPage2.Controls);
        }


        void SetEnable(bool f)
        {
            // NẾU là admin thì cho phép mở
            cbtypeoffee.Enabled = f;
            ckcontract.Enabled = f;
            ckcompleted.Enabled = f;

            txtfirstname.Enabled = f;
            txtlastname.Enabled = f;
            memoEdit_noisinh.Enabled = f;
            ckcontract.Enabled = f;
            txtcode.Enabled = f;
            txtaddress.Enabled = f;
            txtemail.Enabled = f;
            txtnote.Enabled = f;
            txtphonenum.Enabled = f;
            dateEdit_dateofbirth.Enabled = f;
            buttonEdit_Status.Enabled = f;
            buttonEdit_Channel.Enabled = f;
            comboboxUC_Classold.Enabled = f;
            //    ClassTemp = f;

            cbsex.Enabled = f;


            txtcmnd.Enabled = f;

            ckinfo.Enabled = f;
            dateedit_register.Enabled = f;
            txtdiscount.Enabled = f;
            spinEdit_price.Enabled = f;

            ckbangquydinh.Enabled = f;
            ckcmnd.Enabled = f;
            ckdonxinnhaphoc.Enabled = f;
            ckhinh46.Enabled = f;
            spinEdit_Money.Enabled = f;
        }

        //khi giam gia dc thay doi thi tinh lai tong học phí
        private void txtdiscount_TextChanged(object sender, EventArgs e)
        {
           // spinEdit_Money.EditValue = TongHocPhi();
        }

        //tinh tổng học phí phải đóng sau khi trừ đi giảm giá và tiền tặng (tiền tặng sẽ được cộng khi học viên giới thiệu người vào học)
        long TongHocPhi()
        {
            try
            {
                #region Old Formula
                //var _class = ((Class)RegisterService.RegisterServices.ClassService.GetByID(ClassID)) ;
                //int Fee = _class.Price;
                //var type =  int.Parse(((TypeOfFee)cbtypeoffee.SelectedItem).ID.ToString());
                //if (type == 2 || type ==4)
                //{
                //    Fee += ValueDefine.donghailan;
                //}
                //if (type == 6)
                //{
                //    Fee += ValueDefine.dongsaulan;
                //}
                //int giamgia = int.Parse(txtdiscount.Text);//%
                //int bonus = int.Parse(spinEdit_price.EditValue.ToString());
                //Fee = Fee - ((Fee / 100) * giamgia);
                //Fee = Fee - bonus;
                //if (StatusID > 0 && StatusID==2 && (long)buttonEdit_Status.Tag!= StatusID)
                //{
                //    var feesave = RegisterService.RegisterServices.ReceiptVoucherFeeService.GetByVoucherFeeSave(long.Parse(StudentID));//lay phi bao luu
                //    Fee = Fee - feesave.Money;
                //    StatusID = 0;
                //}           
                //return Fee;
                #endregion

                #region New Formula
                long Fee = int.Parse(spinEdit_OriginalFee.EditValue.ToString());
                int giamgia = int.Parse(txtdiscount.Text);//%
                int bonus = int.Parse(spinEdit_price.EditValue.ToString());
                Fee = Fee - ((Fee / 100) * giamgia);
                Fee = Fee - bonus;
                if (StatusID > 0 && StatusID == 2 && (long)buttonEdit_Status.Tag != StatusID)
                {
                    var feesave = RegisterService.RegisterServices.ReceiptVoucherFeeService.GetByVoucherFeeSave(long.Parse(StudentID));//lay phi bao luu
                    Fee = Fee - feesave.Money;
                    StatusID = 0;
                }
                return Fee;
                #endregion
            }
            catch {
                return 0;
            }
        }

        private void spinEdit_price_EditValueChanged(object sender, EventArgs e)
        {
            //spinEdit_Money.EditValue = TongHocPhi();
        }

        private void txtdiscount_EditValueChanged(object sender, EventArgs e)
        {
            //spinEdit_Money.EditValue = TongHocPhi();
        }



        private void cbtypeoffee_SelectedIndexChanged(object sender, EventArgs e)
        {
            //spinEdit_Money.EditValue = TongHocPhi();
        }

        private void buttonEdit_Class_ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            frmSelectClass frm = new frmSelectClass();
            if (frm.ShowDialog() == DialogResult.OK)
            {
                buttonEdit_Class.EditValue = frm.Name;
                ClassID = frm.ID;
                dateedit_dateaddmisstion.DateTime = ((Class)RegisterService.RegisterServices.ClassService.GetByID(ClassID)).StartDate;
               if(ID<=0)
                   txtcode.Text = RegisterService.RegisterServices.StudentService.GenerateCode(ClassID);
            }
        
            else
            {
                if (((string)buttonEdit_Class.EditValue) == "")
                {
                    buttonEdit_Class.EditValue = "";
                    dateedit_dateaddmisstion.DateTime = DateTime.Now;
                    ClassID = 0;
                }
            }
            spinEdit_Money.EditValue = TongHocPhi();
        }

        private void buttonEdit_Channel_ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            frmSelectChannel br = new frmSelectChannel();
            if (br.ShowDialog() == DialogResult.OK)
            {

                buttonEdit_Channel.Tag = br.ID;
                buttonEdit_Channel.Text = br.Name;
            }
            else
            {

                buttonEdit_Channel.Tag = 0;
                buttonEdit_Channel.Text = string.Empty;
            }
        }

        private void buttonEdit_Status_ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            frmSelectStudentStatus br = new frmSelectStudentStatus(1);
            if (br.ShowDialog() == DialogResult.OK)
            {

                buttonEdit_Status.Tag = br.ID;
                buttonEdit_Status.Text = br.Name;
            }
            else
            {

                buttonEdit_Status.Tag = 0;
                buttonEdit_Status.Text = string.Empty;
            }
        }

        private void cmdcalculateFee_Click(object sender, EventArgs e)
        {
            spinEdit_Money.EditValue = TongHocPhi();
        }

        private void cmdXemBaoluu_Click(object sender, EventArgs e)
        {
            frmStudentReserve form = new frmStudentReserve();
            form.Show();
        }

     
     
    }
}
